---
title: 'Replication: Advocates of Climate Action? The Age of Members of Parliament
  and their Activity in Legislative Debates on Climate Change'
author: "Marc Debus & Noam Himmelrath"
date: "6/30/2022"
output: html_document
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

p_needed <-
  c( "viridis", "stargazer", "stringr", "legislatoR", "dplyr", "XML", "foreign", "MASS", "readxl", "quanteda", "ggplot2", "sjPlot", "effects", "ggpubr")

packages <- rownames(installed.packages())

p_to_install <- p_needed[!(p_needed %in% packages)]

if (length(p_to_install) > 0) {
  install.packages(p_to_install)
}

sapply(p_needed, require, character.only = TRUE)

# This is an option for stargazer tables
# It automatically adapts the output to html or latex,
# depending on whether we want a html or pdf file
stargazer_opt <- ifelse(knitr::is_latex_output(), "latex", "html")
```



```{r load data}
load("speeches.RData")
load("mdb_dta.RData")
```



```{r saliency of climate over the years}
# creata new data frame for young MPs
plot2013y <- nrow(speeches[speeches$year == 2013 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2013 & speeches$age <= 40,])
plot2014y <- nrow(speeches[speeches$year == 2014 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2014 & speeches$age <= 40,])
plot2015y <- nrow(speeches[speeches$year == 2015 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2015 & speeches$age <= 40,])
plot2016y <- nrow(speeches[speeches$year == 2016 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2016 & speeches$age <= 40,])
plot2017y <- nrow(speeches[speeches$year == 2017 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2017 & speeches$age <= 40,])
plot2018y <- nrow(speeches[speeches$year == 2018 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2018 & speeches$age <= 40,])
plot2019y <- nrow(speeches[speeches$year == 2019 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2019 & speeches$age <= 40,])
plot2020y <- nrow(speeches[speeches$year == 2020 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2020 & speeches$age <= 40,])
plot2021y <- nrow(speeches[speeches$year == 2021 & speeches$dummy_climate == 1 & speeches$age <= 40,])/nrow(speeches[speeches$year == 2021 & speeches$age <= 40,])

plot2013o <- nrow(speeches[speeches$year == 2013 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2013 & speeches$age > 40,])
plot2014o <- nrow(speeches[speeches$year == 2014 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2014 & speeches$age > 40,])
plot2015o <- nrow(speeches[speeches$year == 2015 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2015 & speeches$age > 40,])
plot2016o <- nrow(speeches[speeches$year == 2016 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2016 & speeches$age > 40,])
plot2017o <- nrow(speeches[speeches$year == 2017 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2017 & speeches$age > 40,])
plot2018o <- nrow(speeches[speeches$year == 2018 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2018 & speeches$age > 40,])
plot2019o <- nrow(speeches[speeches$year == 2019 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2019 & speeches$age > 40,])
plot2020o <- nrow(speeches[speeches$year == 2020 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2020 & speeches$age > 40,])
plot2021o <- nrow(speeches[speeches$year == 2021 & speeches$dummy_climate == 1 & speeches$age > 40,])/nrow(speeches[speeches$year == 2021 & speeches$age > 40,])




year <- c(2013:2021)
plotdta <- as.data.frame(cbind(c(plot2013y, plot2014y, plot2015y, plot2016y, plot2017y, plot2018y, plot2019y, plot2020y, plot2021y), c(plot2013o, plot2014o, plot2015o, plot2016o, plot2017o, plot2018o, plot2019o, plot2020o, plot2021o), year))
colnames(plotdta) <- c("meanyoung", "meanold", "year")

#create Figure 3 from paper
lines <- ggplot() +
    geom_line(data=plotdta, aes(x=year, y = meanyoung, color = "40 years and younger"))  +
    geom_line(data=plotdta, aes(x=year, y = meanold, color = "Older than 40 years")) +
    scale_x_continuous(labels=as.character(year),breaks=year) +
    labs(x = "Year", y = "Average Share of Speeches on Climate Change among all Speeches") +
    scale_color_manual(name = "MPs' Age ", values = c( "Older than 40 years" = "grey", "40 years and younger" = "black")) 

lines
```
```{r line plot}
#safe plot
pdf(file="saliency.pdf")
lines
dev.off()
```


```{r aggregate on MP level}
# aggregate individual speeches and mean age of MPs on MP-level
MP_level_speeches <- aggregate(speeches$dummy_climate,
                              by = list(speeches$speaker, speeches$wp),
                              FUN = sum)

colnames(MP_level_speeches) <- c("name", "wp", "climate_speechcount")

speeches$age <- as.numeric(speeches$age)
MP_level_age <- aggregate(speeches$age,
                              by = list(speeches$speaker, speeches$wp),
                              FUN = mean)

colnames(MP_level_age) <- c("name", "wp", "age")

#left_join
MP_level_speeches <- left_join(MP_level_speeches, MP_level_age)

MP_level_speeches <- left_join(MP_level_speeches, mdb_dta, by = c("name" = "full_name", "wp"="wp"))


# create directly elected dummy
for (i in 1:nrow(MP_level_speeches)) {
  MP_level_speeches$direct[i] <- ifelse(MP_level_speeches$mandate[i] == "Direktwahl", 1, 0)
}

# create female dummy
for (i in 1:nrow(MP_level_speeches)) {
  MP_level_speeches$female[i] <- ifelse(MP_level_speeches$sex[i] == "female", 1, 0)
}



# fix dezimal numbers ( "," -> ".")
MP_level_speeches$share_below_18 <- as.numeric(sub(",", ".", MP_level_speeches$share_below_18, fixed = TRUE))
MP_level_speeches$share18_24 <- as.numeric(sub(",", ".", MP_level_speeches$share18_24, fixed = TRUE))
MP_level_speeches$share25_34 <- as.numeric(sub(",", ".", MP_level_speeches$share25_34, fixed = TRUE))
MP_level_speeches$share35_59 <- as.numeric(sub(",", ".", MP_level_speeches$share35_59, fixed = TRUE))
MP_level_speeches$share60_74 <- as.numeric(sub(",", ".", MP_level_speeches$share60_74, fixed = TRUE))
MP_level_speeches$share_above_75 <- as.numeric(sub(",", ".", MP_level_speeches$share_above_75, fixed = TRUE))


# create age cohorts
for (i in 1:nrow(MP_level_speeches)) {
  MP_level_speeches$share_below_35[i] <- MP_level_speeches$share_below_18[i] + MP_level_speeches$share18_24[i] + MP_level_speeches$share25_34[i]
}


for (i in 1:nrow(MP_level_speeches)) {
  MP_level_speeches$share_above_60[i] <- MP_level_speeches$share60_74[i] + MP_level_speeches$share_above_75[i]
}


MP_level_speeches$share_below_35 <- as.numeric(sub(",", ".", MP_level_speeches$share_below_35, fixed = TRUE))
MP_level_speeches$share_above_60 <- as.numeric(sub(",", ".", MP_level_speeches$share_above_60, fixed = TRUE))

# economy control

MP_level_speeches$share_no_job <- as.numeric(sub(",", ".", MP_level_speeches$share_no_job, fixed = TRUE))

# committee membership

climate_com_18 <- c("Bärbel Höhn", "Artur Auernhammer", "Marie-Luise Dött", "Thomas Gebhart", "Josef Göppel", "Oliver Grundmann", "Christian Haase", "Sylvia Jörrißen", "Steffen Kanitz", "Yvonne Magwas", "Matern von Marschall", "Karsten Möring", "Carsten Müller", "Ulrich Petzold", "Klaus-Peter Schulze", "Volkmar Vogel", "Kai Wegner", "Anja Weisgerber", "Marco Bülow", "Michael Groß", "Hiltrud Lotze", "Matthias Miersch", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Frank Schwabe", "Claudia Tausend", "Michael Thews", "Carsten Träger", "Caren Lay", "Ralph Lenkert", "Birgit Menz", "Hubertus Zdebel", "Sylvia Kotting-Uhl", "Christian Kühn", "Steffi Lemke", "Peter Meiwald"
                    , "Thoomas Bareiß", "Sybille Benning", "Herlind Gundelach", "Olav Gutting",  "Mark Helfrich", "Andreas Jung", "Rüdiger Kruse", "Uwe Lagosky", "Philipp Graf von und zu Lerchenfeld", "Jan-Marco Luczak", "Georg Nüßlein", "Florian Oßner", "Eckhard Pols", "Oliver Wittke", "Barbara Woltmann", "Matthias Zimmer", "Sören Bartol", "Martin Bukert", "Bernhard Daldrup", "Marcus Held", "Steffen-Claudio Lemme", "Birgit Malecha-Nissen", "René Röspel", "Nina Scheer", "Elfi Scho-Antwerpes", "Ute Vogt", "Heidrun Bluhm", "Eva Bulling-Schröter", "Kirsten Tackmann", "Pia Zimmermann", "Annalena Baerbock", "Lisa Paus", "Julia Verlinden")

climate_com_19 <- c("Sylvia Kotting-Uhl", "Michael Thews", "Astrid Damerow", "Marie-Luise Dött", "Hermann Färber", "Oliver Grundmann", "Christian Hirte", "Michael Kießling", "Rüdiger Kruse", "Karsten Möring", "Klaus-Peter Schulze", "Torsten Schweiger", "Björn Simon", "Kai Wegner", "Anja Weisgerber", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Nina Scheer", "Michael Schrodi", "Frank Schwabe", "Carsten Träger", "Marc Bernhard", "Andreas Bleck", "Karsten Hilse", "Rainer Kraft", "Heiko Wildberg", "Grigorios Aggelidis", "Olaf in der Beek", "Lukas Köhler", "Judith Skudelny", "Caren Lay", "Ralph Lenkert", "Eva-Maria Schreiber", "Hubertus Zdebel", "Lisa Badum", "Bettina Hoffmann", "Steffi Lemke"
                 , "Michael von Abercron", "Sybille Benning", "Ingo Gädechens", "Christian Haase", "Alexander Krauß", "Daniela Ludwig", "Florian Oßner", "Eckhard Pols", "Johannes Röring", "Stefan Sauer", "Reinhold Sendker", "Bernd Siebert", "Stephan Stracke", "Hans-Jürgen Thies", "Bela Bach", "Timon Gremmels", "Metin Hakverdi", "Marcus Held", "Arno Klare", "Isabel Mackensen", "Matthias Miersch", "René Röspel", "Udo Theodor Hemmelgarn", "Frank Magnitz", "Stephan Protschka", "Dirk Spaniel", "Karlheinz Busen", "Christoph Meyer", "Martin Neumann", "Frank Sitta", "Lorenz Gösta Beutin", "Victor Perli", "Ingrid Remmers", "Harald Weinberg", "Harald Ebner", "Oliver Krischer", "Christian Kühn", "Julia Verlinden", "Marco Bülow"
                 )

MP_level_speeches$commember <- NA

for (i in 1:nrow(MP_level_speeches)){
  MP_level_speeches$commember[i] <- ifelse(MP_level_speeches$name[i] %in% climate_com_18 & MP_level_speeches$wp[i] == 18, 1,
                                          ifelse(MP_level_speeches$name[i] %in% climate_com_19 & MP_level_speeches$wp[i] == 19, 1, 0))
}


# add government dummy

MP_level_speeches$mem_gov_party <- NA

for (i in 1:nrow(MP_level_speeches)) {
MP_level_speeches$mem_gov_party[i] <- ifelse(MP_level_speeches$party[i] %in% c("Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union", "Fraktion der Sozialdemokratischen Partei Deutschlands"), 1, 0)
}

# rename parties from parliamentary group to actual parties

MP_level_speeches$party[MP_level_speeches$party == "Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union"] <- "CDU/CSU"

MP_level_speeches$party[MP_level_speeches$party == "Fraktion Bündnis 90/Die Grünen"] <- "Greens"

MP_level_speeches$party[MP_level_speeches$party == "Alternative für Deutschland"] <- "AfD"

MP_level_speeches$party[MP_level_speeches$party == "Fraktion der Freien Demokratischen Partei"] <- "FDP"

MP_level_speeches$party[MP_level_speeches$party == "Fraktion der Sozialdemokratischen Partei Deutschlands"] <- "SPD"

MP_level_speeches$party[MP_level_speeches$party == "Fraktion DIE LINKE."] <- "The Left"

# remove MPs without party

table(MP_level_speeches$party)

MP_level_speeches <- MP_level_speeches[MP_level_speeches$party %in% c("CDU/CSU","Greens", "AfD","FDP", "SPD", "The Left"),]

# add seat share variable (data from ParlGov data set)

MP_level_speeches$seatshare <- NA

# EP 18
MP_level_speeches$seatshare[MP_level_speeches$party == "CDU/CSU" & MP_level_speeches$wp == 18] <- 49.29

MP_level_speeches$seatshare[MP_level_speeches$party == "Greens" & MP_level_speeches$wp == 18] <- 9.98

MP_level_speeches$seatshare[MP_level_speeches$party == "The Left" & MP_level_speeches$wp == 18] <- 10.14

MP_level_speeches$seatshare[MP_level_speeches$party == "SPD" & MP_level_speeches$wp == 18] <- 30.59

# EP 19
MP_level_speeches$seatshare[MP_level_speeches$party == "CDU/CSU" & MP_level_speeches$wp == 19] <- 34.7

MP_level_speeches$seatshare[MP_level_speeches$party == "Greens" & MP_level_speeches$wp == 19] <- 9.4

MP_level_speeches$seatshare[MP_level_speeches$party == "The Left" & MP_level_speeches$wp == 19] <- 9.7

MP_level_speeches$seatshare[MP_level_speeches$party == "SPD" & MP_level_speeches$wp == 19] <- 21.6

MP_level_speeches$seatshare[MP_level_speeches$party == "FDP" & MP_level_speeches$wp == 19] <- 11.3

MP_level_speeches$seatshare[MP_level_speeches$party == "AfD" & MP_level_speeches$wp == 19] <- 13.3


# add parliamentary group leader dummy

MP_level_speeches$parlgroupleader <- NA

#EP18
MP_level_speeches$parlgroupleader[MP_level_speeches$name %in% c("Volker Kauder", # CDU
                                                                  "Frank-Walter Steinmeier", "Thomas Oppermann", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Gregor Gysi", "Dietmar Bartsch", "Sarah Wagenknecht" #The Left
                                                                  ) & MP_level_speeches$wp == 18] <- 1
                                   
#EP19
MP_level_speeches$parlgroupleader[MP_level_speeches$name %in% c("Christian Lindner", #FDP
                                                                  "Ralph Brinkhaus", # CDU
                                                                  "Rolf Mützenich", "Andrea Nahles", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Dietmar Bartsch", "Amira Mohamed Ali", #The Left
                                                                  "Alice Weidel", "Eberhardt Alexander Gauland" #AfD
                                                                  ) & MP_level_speeches$wp == 19] <- 1
MP_level_speeches$parlgroupleader[is.na(MP_level_speeches$parlgroupleader)] <- 0
```

```{r data for models, echo = FALSE}
X <- as.data.frame(MP_level_speeches[, c("climate_speechcount", "age", "share_below_35", "share35_59", "share_above_60", "commember", 
                                           "party", "direct", "female", "expdummy", "parlgroupleader", "seatshare", "share_no_job", "wp")])


# change reference categorie for "party"-variable from AfD to CDU

X$party <- relevel(factor(X$party), ref="CDU/CSU") 
```


```{r regression, echo = FALSE}
m1  <- glm.nb(climate_speechcount ~ age
              + share_below_35
           #  + share35_59
           #  + share_above_60
              + commember
              #+ party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
              + seatshare
              + share_no_job
              , data = X)


m2 <- glm.nb(climate_speechcount ~ age
              + share_below_35
         #   + share35_59
          #    + share_above_60
              + commember
              + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
            #  + seatshare
              + share_no_job
              , data = X)

m3 <- glm.nb(climate_speechcount ~ age
              + share_below_35
           #   + share35_59
           #   + share_above_60
              + commember
             # + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
              + parlgroupleader
              + seatshare
              + share_no_job
              , data = X)


# creates Table 1 from the paper
stargazer(m1,m2,m3,
          title  = "Negative Binomial Models of Speeches on Climate Change",
          #label = "Table 2",
         # covariate.labels = c("Age", "Constituency share below 35"
                               #,"Constituency share 35-59", "Constituency share above 60"
      #                         , "Committee Member", "CDU/CSU", "FDP", "Greens", "SPD", "The Left", "Directly Elected", "Female", "Reelected", "Parl. Group Leader", "Party Seatshare", "Unemployment rate in Constituency"),
          dep.var.caption = "Negative Binomial Model",
          dep.var.labels =  "Speeches on Climate Change",
          #type = stargazer_opt,
          type = "text",
          header = F,
          column.sep.width = "0.5pt",
          out = "table1.doc")
```

```{r plot dv hist}
# creates Figure 2 from the paper
pdf(file="dv_hist.pdf")
hist(X$climate_speechcount, 
     main = NULL,
     xlab = "Number of Speeches on Climate Change by MP per EP",
     border = F,
     las = 1,
     font.main = 1,                          # if you want to "unbold" the caption
     cex.main = 1,                         # control caption font size
     bty = "n")                             # no box around the plot))
dev.off()
```


```{r plot effect}
# creates Figure 4 from the paper
pdf(file="effect_sim.pdf")
plot_model(m1, type = "eff", terms = "age", title = "", axis.title = c("MPs' Age in Years", "Estimated Number of Speeches on Climate Change"))
dev.off()
```

# Per Year Analysis (Robustness not in paper)

Aggregate on MP per Year level

```{r aggregate data on year level}
#aggregate individual speeches and mean age of MPs on MP-level
MP_year_speeches <- aggregate(speeches$dummy_climate,
                              by = list(speeches$speaker, speeches$year),
                              FUN = sum)

colnames(MP_year_speeches) <- c("name", "year", "climate_speechcount")

MP_year_age <- aggregate(speeches$age,
                              by = list(speeches$speaker, speeches$year),
                              FUN = mean)

colnames(MP_year_age) <- c("name", "year", "age")

MP_year_speeches <- left_join(MP_year_speeches, MP_year_age)

MP_year_speeches$wp[MP_year_speeches$year %in% c(2013,2014,2015,2016, 2017)] <- 18
MP_year_speeches$wp[MP_year_speeches$year %in% c(2018,2019,2020,2021)] <- 19

MP_year_speeches <- left_join(MP_year_speeches, mdb_dta, by = c("name" = "full_name", "wp"="wp")) 



## create directly elected dummy
for (i in 1:nrow(MP_year_speeches)) {
  MP_year_speeches$direct[i] <- ifelse(MP_year_speeches$mandate[i] == "Direktwahl", 1, 0)
}

##create female dummy
for (i in 1:nrow(MP_year_speeches)) {
  MP_year_speeches$female[i] <- ifelse(MP_year_speeches$sex[i] == "female", 1, 0)
}



# fix dezimal numbers ( "," -> ".")
MP_year_speeches$share_below_18 <- as.numeric(sub(",", ".", MP_year_speeches$share_below_18, fixed = TRUE))
MP_year_speeches$share18_24 <- as.numeric(sub(",", ".", MP_year_speeches$share18_24, fixed = TRUE))
MP_year_speeches$share25_34 <- as.numeric(sub(",", ".", MP_year_speeches$share25_34, fixed = TRUE))
MP_year_speeches$share35_59 <- as.numeric(sub(",", ".", MP_year_speeches$share35_59, fixed = TRUE))
MP_year_speeches$share60_74 <- as.numeric(sub(",", ".", MP_year_speeches$share60_74, fixed = TRUE))
MP_year_speeches$share_above_75 <- as.numeric(sub(",", ".", MP_year_speeches$share_above_75, fixed = TRUE))


# create age cohorts
for (i in 1:nrow(MP_year_speeches)) {
  MP_year_speeches$share_below_35[i] <- MP_year_speeches$share_below_18[i] + MP_year_speeches$share18_24[i] + MP_year_speeches$share25_34[i]
}


for (i in 1:nrow(MP_year_speeches)) {
  MP_year_speeches$share_above_60[i] <- MP_year_speeches$share60_74[i] + MP_year_speeches$share_above_75[i]
}


MP_year_speeches$share_below_35 <- as.numeric(sub(",", ".", MP_year_speeches$share_below_35, fixed = TRUE))
MP_year_speeches$share_above_60 <- as.numeric(sub(",", ".", MP_year_speeches$share_above_60, fixed = TRUE))

# economy control

MP_year_speeches$share_no_job <- as.numeric(sub(",", ".", MP_year_speeches$share_no_job, fixed = TRUE))

# committee membership

climate_com_18 <- c("Bärbel Höhn", "Artur Auernhammer", "Marie-Luise Dött", "Thomas Gebhart", "Josef Göppel", "Oliver Grundmann", "Christian Haase", "Sylvia Jörrißen", "Steffen Kanitz", "Yvonne Magwas", "Matern von Marschall", "Karsten Möring", "Carsten Müller", "Ulrich Petzold", "Klaus-Peter Schulze", "Volkmar Vogel", "Kai Wegner", "Anja Weisgerber", "Marco Bülow", "Michael Groß", "Hiltrud Lotze", "Matthias Miersch", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Frank Schwabe", "Claudia Tausend", "Michael Thews", "Carsten Träger", "Caren Lay", "Ralph Lenkert", "Birgit Menz", "Hubertus Zdebel", "Sylvia Kotting-Uhl", "Christian Kühn", "Steffi Lemke", "Peter Meiwald"
                    , "Thoomas Bareiß", "Sybille Benning", "Herlind Gundelach", "Olav Gutting",  "Mark Helfrich", "Andreas Jung", "Rüdiger Kruse", "Uwe Lagosky", "Philipp Graf von und zu Lerchenfeld", "Jan-Marco Luczak", "Georg Nüßlein", "Florian Oßner", "Eckhard Pols", "Oliver Wittke", "Barbara Woltmann", "Matthias Zimmer", "Sören Bartol", "Martin Bukert", "Bernhard Daldrup", "Marcus Held", "Steffen-Claudio Lemme", "Birgit Malecha-Nissen", "René Röspel", "Nina Scheer", "Elfi Scho-Antwerpes", "Ute Vogt", "Heidrun Bluhm", "Eva Bulling-Schröter", "Kirsten Tackmann", "Pia Zimmermann", "Annalena Baerbock", "Lisa Paus", "Julia Verlinden")

climate_com_19 <- c("Sylvia Kotting-Uhl", "Michael Thews", "Astrid Damerow", "Marie-Luise Dött", "Hermann Färber", "Oliver Grundmann", "Christian Hirte", "Michael Kießling", "Rüdiger Kruse", "Karsten Möring", "Klaus-Peter Schulze", "Torsten Schweiger", "Björn Simon", "Kai Wegner", "Anja Weisgerber", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Nina Scheer", "Michael Schrodi", "Frank Schwabe", "Carsten Träger", "Marc Bernhard", "Andreas Bleck", "Karsten Hilse", "Rainer Kraft", "Heiko Wildberg", "Grigorios Aggelidis", "Olaf in der Beek", "Lukas Köhler", "Judith Skudelny", "Caren Lay", "Ralph Lenkert", "Eva-Maria Schreiber", "Hubertus Zdebel", "Lisa Badum", "Bettina Hoffmann", "Steffi Lemke"
                 , "Michael von Abercron", "Sybille Benning", "Ingo Gädechens", "Christian Haase", "Alexander Krauß", "Daniela Ludwig", "Florian Oßner", "Eckhard Pols", "Johannes Röring", "Stefan Sauer", "Reinhold Sendker", "Bernd Siebert", "Stephan Stracke", "Hans-Jürgen Thies", "Bela Bach", "Timon Gremmels", "Metin Hakverdi", "Marcus Held", "Arno Klare", "Isabel Mackensen", "Matthias Miersch", "René Röspel", "Udo Theodor Hemmelgarn", "Frank Magnitz", "Stephan Protschka", "Dirk Spaniel", "Karlheinz Busen", "Christoph Meyer", "Martin Neumann", "Frank Sitta", "Lorenz Gösta Beutin", "Victor Perli", "Ingrid Remmers", "Harald Weinberg", "Harald Ebner", "Oliver Krischer", "Christian Kühn", "Julia Verlinden", "Marco Bülow"
                 )

MP_year_speeches$commember <- NA

for (i in 1:nrow(MP_year_speeches)){
  MP_year_speeches$commember[i] <- ifelse(MP_year_speeches$name[i] %in% climate_com_18 & MP_year_speeches$wp[i] == 18, 1,
                                          ifelse(MP_year_speeches$name[i] %in% climate_com_19 & MP_year_speeches$wp[i] == 19, 1, 0))
}


# add government dummy

MP_year_speeches$mem_gov_party <- NA

for (i in 1:nrow(MP_year_speeches)) {
MP_year_speeches$mem_gov_party[i] <- ifelse(MP_year_speeches$party[i] %in% c("Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union", "Fraktion der Sozialdemokratischen Partei Deutschlands"), 1, 0)
}

# rename parties from parliamentary group to actual parties

MP_year_speeches$party[MP_year_speeches$party == "Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union"] <- "CDU/CSU"

MP_year_speeches$party[MP_year_speeches$party == "Fraktion Bündnis 90/Die Grünen"] <- "Greens"

MP_year_speeches$party[MP_year_speeches$party == "Alternative für Deutschland"] <- "AfD"

MP_year_speeches$party[MP_year_speeches$party == "Fraktion der Freien Demokratischen Partei"] <- "FDP"

MP_year_speeches$party[MP_year_speeches$party == "Fraktion der Sozialdemokratischen Partei Deutschlands"] <- "SPD"

MP_year_speeches$party[MP_year_speeches$party == "Fraktion DIE LINKE."] <- "The Left"

# remove MPs without party

table(MP_year_speeches$party)

MP_year_speeches <- MP_year_speeches[MP_year_speeches$party %in% c("CDU/CSU","Greens", "AfD","FDP", "SPD", "The Left"),]

# add seat share variable (data from ParlGov data set)
MP_year_speeches$seatshare <- NA

#EP 18
MP_year_speeches$seatshare[MP_year_speeches$party == "CDU/CSU" & MP_year_speeches$wp == 18] <- 49.29

MP_year_speeches$seatshare[MP_year_speeches$party == "Greens" & MP_year_speeches$wp == 18] <- 9.98

MP_year_speeches$seatshare[MP_year_speeches$party == "The Left" & MP_year_speeches$wp == 18] <- 10.14

MP_year_speeches$seatshare[MP_year_speeches$party == "SPD" & MP_year_speeches$wp == 18] <- 30.59

#EP19
MP_year_speeches$seatshare[MP_year_speeches$party == "CDU/CSU" & MP_year_speeches$wp == 19] <- 34.7

MP_year_speeches$seatshare[MP_year_speeches$party == "Greens" & MP_year_speeches$wp == 19] <- 9.4

MP_year_speeches$seatshare[MP_year_speeches$party == "The Left" & MP_year_speeches$wp == 19] <- 9.7

MP_year_speeches$seatshare[MP_year_speeches$party == "SPD" & MP_year_speeches$wp == 19] <- 21.6

MP_year_speeches$seatshare[MP_year_speeches$party == "FDP" & MP_year_speeches$wp == 19] <- 11.3

MP_year_speeches$seatshare[MP_year_speeches$party == "AfD" & MP_year_speeches$wp == 19] <- 13.3


#add parliamentary group leader dummy

MP_year_speeches$parlgroupleader <- NA

#EP18
MP_year_speeches$parlgroupleader[MP_year_speeches$name %in% c("Volker Kauder", # CDU
                                                                  "Frank-Walter Steinmeier", "Thomas Oppermann", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Gregor Gysi", "Dietmar Bartsch", "Sarah Wagenknecht" #The Left
                                                                  ) & MP_year_speeches$wp == 18] <- 1
                                   
#EP19
MP_year_speeches$parlgroupleader[MP_year_speeches$name %in% c("Christian Lindner", #FDP
                                                                  "Ralph Brinkhaus", # CDU
                                                                  "Rolf Mützenich", "Andrea Nahles", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Dietmar Bartsch", "Amira Mohamed Ali", #The Left
                                                                  "Alice Weidel", "Eberhardt Alexander Gauland" #AfD
                                                                  ) & MP_year_speeches$wp == 19] <- 1
MP_year_speeches$parlgroupleader[is.na(MP_year_speeches$parlgroupleader)] <- 0
```

```{r data for models, echo = FALSE}
Y <- as.data.frame(MP_year_speeches[, c("climate_speechcount", "age", "share_below_35", "share35_59", "share_above_60", "commember", 
                                           "party", "direct", "female", "expdummy", "parlgroupleader", "seatshare", "share_no_job", "wp", "year")])


```


```{r regression, echo = FALSE}
m4  <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
              #+ party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
              + seatshare
              + share_no_job
              , data = Y)


m5 <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
              + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
            #  + seatshare
              + share_no_job
              , data = Y)

m6 <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
             # + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
              + seatshare
              + share_no_job
              , data = Y)


stargazer(m4,m5,m6,
          title  = "Negative Binomial Models of Speeches on Climate Change",
          #label = "Table 2",
          #covariate.labels = c("Age", "Constituency share below 35","Constituency share 35-59", "Constituency share above 60", "Committee Member", "CDU/CSU", "FDP", "Greens", "SPD", "The Left", "Directly Elected", "Female", "Reelected", "Parl. Group Leader", "Party Seatshare", "Unemployment rate in Constituency"),
          dep.var.caption = "Negative Binomial Model",
          dep.var.labels =  "Speeches on Climate Change",
          #type = stargazer_opt,
          type = "text",
          header = F,
          column.sep.width = "0.5pt")
```




# 2nd part: Discriminate between before and after 2019
Aggregate on  2019 threshold: pre 2019

```{r robustness 2 aggregate on MP/year after 2019}
# split speeches data
speeches1318 <- speeches[speeches$year < 2019,]

speeches1921 <- speeches[speeches$year %in% c(2019,2020,2021),]


# First: speeches after 2019

#aggregate individual speeches and mean age of MPs on MP-level
MP_2019_speeches <- aggregate(speeches1921$dummy_climate,
                              by = list(speeches1921$speaker, speeches1921$year),
                              FUN = sum)

colnames(MP_2019_speeches) <- c("name", "year", "climate_speechcount")

speeches1921$age <- as.numeric(speeches1921$age)
MP_2019_age <- aggregate(speeches1921$age,
                              by = list(speeches1921$speaker, speeches1921$year),
                              FUN = mean)

colnames(MP_2019_age) <- c("name", "year", "age")

MP_2019_speeches <- left_join(MP_2019_speeches, MP_2019_age)


MP_2019_speeches$wp[MP_2019_speeches$year %in% c(2013,2014,2015,2016, 2017)] <- 18
MP_2019_speeches$wp[MP_2019_speeches$year %in% c(2018,2019,2020,2021)] <- 19

MP_2019_speeches <- left_join(MP_2019_speeches, mdb_dta, by = c("name" = "full_name", "wp"="wp"))


## create directly elected dummy
for (i in 1:nrow(MP_2019_speeches)) {
  MP_2019_speeches$direct[i] <- ifelse(MP_2019_speeches$mandate[i] == "Direktwahl", 1, 0)
}

##create female dummy
for (i in 1:nrow(MP_2019_speeches)) {
  MP_2019_speeches$female[i] <- ifelse(MP_2019_speeches$sex[i] == "female", 1, 0)
}



# fix dezimal numbers ( "," -> ".")
MP_2019_speeches$share_below_18 <- as.numeric(sub(",", ".", MP_2019_speeches$share_below_18, fixed = TRUE))
MP_2019_speeches$share18_24 <- as.numeric(sub(",", ".", MP_2019_speeches$share18_24, fixed = TRUE))
MP_2019_speeches$share25_34 <- as.numeric(sub(",", ".", MP_2019_speeches$share25_34, fixed = TRUE))
MP_2019_speeches$share35_59 <- as.numeric(sub(",", ".", MP_2019_speeches$share35_59, fixed = TRUE))
MP_2019_speeches$share60_74 <- as.numeric(sub(",", ".", MP_2019_speeches$share60_74, fixed = TRUE))
MP_2019_speeches$share_above_75 <- as.numeric(sub(",", ".", MP_2019_speeches$share_above_75, fixed = TRUE))


# create age cohorts
for (i in 1:nrow(MP_2019_speeches)) {
  MP_2019_speeches$share_below_35[i] <- MP_2019_speeches$share_below_18[i] + MP_2019_speeches$share18_24[i] + MP_2019_speeches$share25_34[i]
}


for (i in 1:nrow(MP_2019_speeches)) {
  MP_2019_speeches$share_above_60[i] <- MP_2019_speeches$share60_74[i] + MP_2019_speeches$share_above_75[i]
}


MP_2019_speeches$share_below_35 <- as.numeric(sub(",", ".", MP_2019_speeches$share_below_35, fixed = TRUE))
MP_2019_speeches$share_above_60 <- as.numeric(sub(",", ".", MP_2019_speeches$share_above_60, fixed = TRUE))

# economy control

MP_2019_speeches$share_no_job <- as.numeric(sub(",", ".", MP_2019_speeches$share_no_job, fixed = TRUE))

# committee membership

climate_com_19 <- c("Sylvia Kotting-Uhl", "Michael Thews", "Astrid Damerow", "Marie-Luise Dött", "Hermann Färber", "Oliver Grundmann", "Christian Hirte", "Michael Kießling", "Rüdiger Kruse", "Karsten Möring", "Klaus-Peter Schulze", "Torsten Schweiger", "Björn Simon", "Kai Wegner", "Anja Weisgerber", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Nina Scheer", "Michael Schrodi", "Frank Schwabe", "Carsten Träger", "Marc Bernhard", "Andreas Bleck", "Karsten Hilse", "Rainer Kraft", "Heiko Wildberg", "Grigorios Aggelidis", "Olaf in der Beek", "Lukas Köhler", "Judith Skudelny", "Caren Lay", "Ralph Lenkert", "Eva-Maria Schreiber", "Hubertus Zdebel", "Lisa Badum", "Bettina Hoffmann", "Steffi Lemke"
                 , "Michael von Abercron", "Sybille Benning", "Ingo Gädechens", "Christian Haase", "Alexander Krauß", "Daniela Ludwig", "Florian Oßner", "Eckhard Pols", "Johannes Röring", "Stefan Sauer", "Reinhold Sendker", "Bernd Siebert", "Stephan Stracke", "Hans-Jürgen Thies", "Bela Bach", "Timon Gremmels", "Metin Hakverdi", "Marcus Held", "Arno Klare", "Isabel Mackensen", "Matthias Miersch", "René Röspel", "Udo Theodor Hemmelgarn", "Frank Magnitz", "Stephan Protschka", "Dirk Spaniel", "Karlheinz Busen", "Christoph Meyer", "Martin Neumann", "Frank Sitta", "Lorenz Gösta Beutin", "Victor Perli", "Ingrid Remmers", "Harald Weinberg", "Harald Ebner", "Oliver Krischer", "Christian Kühn", "Julia Verlinden", "Marco Bülow"
                 )

MP_2019_speeches$commember <- NA

for (i in 1:nrow(MP_2019_speeches)){
  MP_2019_speeches$commember[i] <- ifelse(MP_2019_speeches$name[i] %in% climate_com_19 & MP_2019_speeches$wp[i] == 19, 1, 0)
}


# add government dummy

MP_2019_speeches$mem_gov_party <- NA

for (i in 1:nrow(MP_2019_speeches)) {
MP_2019_speeches$mem_gov_party[i] <- ifelse(MP_2019_speeches$party[i] %in% c("Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union", "Fraktion der Sozialdemokratischen Partei Deutschlands"), 1, 0)
}

#rename parties from parliamentary group to actual parties

MP_2019_speeches$party[MP_2019_speeches$party == "Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union"] <- "CDU/CSU"

MP_2019_speeches$party[MP_2019_speeches$party == "Fraktion Bündnis 90/Die Grünen"] <- "Greens"

MP_2019_speeches$party[MP_2019_speeches$party == "Alternative für Deutschland"] <- "AfD"

MP_2019_speeches$party[MP_2019_speeches$party == "Fraktion der Freien Demokratischen Partei"] <- "FDP"

MP_2019_speeches$party[MP_2019_speeches$party == "Fraktion der Sozialdemokratischen Partei Deutschlands"] <- "SPD"

MP_2019_speeches$party[MP_2019_speeches$party == "Fraktion DIE LINKE."] <- "The Left"

# remove MPs without party

table(MP_2019_speeches$party)

MP_2019_speeches <- MP_2019_speeches[MP_2019_speeches$party %in% c("CDU/CSU","Greens", "AfD","FDP", "SPD", "The Left"),]

# add seat share variable (data from ParlGov data set)
MP_2019_speeches$seatshare <- NA

#WP19
MP_2019_speeches$seatshare[MP_2019_speeches$party == "CDU/CSU" & MP_2019_speeches$wp == 19] <- 34.7

MP_2019_speeches$seatshare[MP_2019_speeches$party == "Greens" & MP_2019_speeches$wp == 19] <- 9.4

MP_2019_speeches$seatshare[MP_2019_speeches$party == "The Left" & MP_2019_speeches$wp == 19] <- 9.7

MP_2019_speeches$seatshare[MP_2019_speeches$party == "SPD" & MP_2019_speeches$wp == 19] <- 21.6

MP_2019_speeches$seatshare[MP_2019_speeches$party == "FDP" & MP_2019_speeches$wp == 19] <- 11.3

MP_2019_speeches$seatshare[MP_2019_speeches$party == "AfD" & MP_2019_speeches$wp == 19] <- 13.3


#add parliamentary group leader dummy

MP_2019_speeches$parlgroupleader <- NA

                                   
#EP
MP_2019_speeches$parlgroupleader[MP_2019_speeches$name %in% c("Christian Lindner", #FDP
                                                                  "Ralph Brinkhaus", # CDU
                                                                  "Rolf Mützenich", "Andrea Nahles", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Dietmar Bartsch", "Amira Mohamed Ali", #The Left
                                                                  "Alice Weidel", "Eberhardt Alexander Gauland" #AfD
                                                                  ) & MP_2019_speeches$wp == 19] <- 1
MP_2019_speeches$parlgroupleader[is.na(MP_2019_speeches$parlgroupleader)] <- 0
```


```{r data for models 3, echo = FALSE}

Z <- as.data.frame(MP_2019_speeches[, c("climate_speechcount", "age", "share_below_35", "share35_59", "share_above_60", "commember", 
                                           "party", "direct", "female", "expdummy", "parlgroupleader", "seatshare", "share_no_job", "wp")])

```

```{r regression 3, echo = FALSE}
m7  <- glm.nb(climate_speechcount ~ age
              + share_below_35
         #     + share35_59
          #    + share_above_60
              + commember
              #+ party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
              + seatshare
              + share_no_job
              , data = Z)


m8 <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
              + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
            #  + seatshare
              + share_no_job
              , data = Z)

m9 <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
             # + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
              + parlgroupleader
              + seatshare
              + share_no_job
              , data = Z)


stargazer(m7,m8,m9,
          title  = "Negative Binomial Models of Speeches on Climate Change per year (20199-2021)" ,
          #label = "Table 2",
          covariate.labels = c("Age", "Constituency share below 35","Constituency share 35-59", "Constituency share above 60", "Committee Member", "CDU/CSU", "FDP", "Greens", "SPD", "The Left", "Directly Elected", "Female", "Reelected", "Parl. Group Leader", "Party Seatshare", "Unemployment rate in Constituency"),
          dep.var.caption = "Negative Binomial Model",
          dep.var.labels =  "Speeches on Climate Change",
          #type = stargazer_opt,
          type = "text",
          header = F,
          column.sep.width = "0.5pt")
```



Speeches until 2019


```{r aggregate data on MP/year level until 2019}
#aggregate individual speeches and mean age of MPs on MP-level
MP_1318_speeches <- aggregate(speeches1318$dummy_climate,
                              by = list(speeches1318$speaker, speeches1318$year),
                              FUN = sum)

colnames(MP_1318_speeches) <- c("name", "year", "climate_speechcount")

MP_1318_age <- aggregate(speeches1318$age,
                              by = list(speeches1318$speaker, speeches1318$year),
                              FUN = mean)

colnames(MP_1318_age) <- c("name", "year", "age")

MP_1318_speeches <- left_join(MP_1318_speeches, MP_1318_age)

MP_1318_speeches$wp[MP_1318_speeches$year %in% c(2013,2014,2015,2016, 2017)] <- 18
MP_1318_speeches$wp[MP_1318_speeches$year %in% c(2018,2019,2020,2021)] <- 19

MP_1318_speeches <- left_join(MP_1318_speeches, mdb_dta, by = c("name" = "full_name", "wp"="wp")) 



## create directly elected dummy
for (i in 1:nrow(MP_1318_speeches)) {
  MP_1318_speeches$direct[i] <- ifelse(MP_1318_speeches$mandate[i] == "Direktwahl", 1, 0)
}

##create female dummy
for (i in 1:nrow(MP_1318_speeches)) {
  MP_1318_speeches$female[i] <- ifelse(MP_1318_speeches$sex[i] == "female", 1, 0)
}



# fix dezimal numbers ( "," -> ".")
MP_1318_speeches$share_below_18 <- as.numeric(sub(",", ".", MP_1318_speeches$share_below_18, fixed = TRUE))
MP_1318_speeches$share18_24 <- as.numeric(sub(",", ".", MP_1318_speeches$share18_24, fixed = TRUE))
MP_1318_speeches$share25_34 <- as.numeric(sub(",", ".", MP_1318_speeches$share25_34, fixed = TRUE))
MP_1318_speeches$share35_59 <- as.numeric(sub(",", ".", MP_1318_speeches$share35_59, fixed = TRUE))
MP_1318_speeches$share60_74 <- as.numeric(sub(",", ".", MP_1318_speeches$share60_74, fixed = TRUE))
MP_1318_speeches$share_above_75 <- as.numeric(sub(",", ".", MP_1318_speeches$share_above_75, fixed = TRUE))


# create age cohorts
for (i in 1:nrow(MP_1318_speeches)) {
  MP_1318_speeches$share_below_35[i] <- MP_1318_speeches$share_below_18[i] + MP_1318_speeches$share18_24[i] + MP_1318_speeches$share25_34[i]
}


for (i in 1:nrow(MP_1318_speeches)) {
  MP_1318_speeches$share_above_60[i] <- MP_1318_speeches$share60_74[i] + MP_1318_speeches$share_above_75[i]
}


MP_1318_speeches$share_below_35 <- as.numeric(sub(",", ".", MP_1318_speeches$share_below_35, fixed = TRUE))
MP_1318_speeches$share_above_60 <- as.numeric(sub(",", ".", MP_1318_speeches$share_above_60, fixed = TRUE))

# economy control

MP_1318_speeches$share_no_job <- as.numeric(sub(",", ".", MP_1318_speeches$share_no_job, fixed = TRUE))

# committee membership

climate_com_18 <- c("Bärbel Höhn", "Artur Auernhammer", "Marie-Luise Dött", "Thomas Gebhart", "Josef Göppel", "Oliver Grundmann", "Christian Haase", "Sylvia Jörrißen", "Steffen Kanitz", "Yvonne Magwas", "Matern von Marschall", "Karsten Möring", "Carsten Müller", "Ulrich Petzold", "Klaus-Peter Schulze", "Volkmar Vogel", "Kai Wegner", "Anja Weisgerber", "Marco Bülow", "Michael Groß", "Hiltrud Lotze", "Matthias Miersch", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Frank Schwabe", "Claudia Tausend", "Michael Thews", "Carsten Träger", "Caren Lay", "Ralph Lenkert", "Birgit Menz", "Hubertus Zdebel", "Sylvia Kotting-Uhl", "Christian Kühn", "Steffi Lemke", "Peter Meiwald"
                    , "Thoomas Bareiß", "Sybille Benning", "Herlind Gundelach", "Olav Gutting",  "Mark Helfrich", "Andreas Jung", "Rüdiger Kruse", "Uwe Lagosky", "Philipp Graf von und zu Lerchenfeld", "Jan-Marco Luczak", "Georg Nüßlein", "Florian Oßner", "Eckhard Pols", "Oliver Wittke", "Barbara Woltmann", "Matthias Zimmer", "Sören Bartol", "Martin Bukert", "Bernhard Daldrup", "Marcus Held", "Steffen-Claudio Lemme", "Birgit Malecha-Nissen", "René Röspel", "Nina Scheer", "Elfi Scho-Antwerpes", "Ute Vogt", "Heidrun Bluhm", "Eva Bulling-Schröter", "Kirsten Tackmann", "Pia Zimmermann", "Annalena Baerbock", "Lisa Paus", "Julia Verlinden")

climate_com_19 <- c("Sylvia Kotting-Uhl", "Michael Thews", "Astrid Damerow", "Marie-Luise Dött", "Hermann Färber", "Oliver Grundmann", "Christian Hirte", "Michael Kießling", "Rüdiger Kruse", "Karsten Möring", "Klaus-Peter Schulze", "Torsten Schweiger", "Björn Simon", "Kai Wegner", "Anja Weisgerber", "Klaus Mindrup", "Ulli Nissen", "Detlev Pilger", "Nina Scheer", "Michael Schrodi", "Frank Schwabe", "Carsten Träger", "Marc Bernhard", "Andreas Bleck", "Karsten Hilse", "Rainer Kraft", "Heiko Wildberg", "Grigorios Aggelidis", "Olaf in der Beek", "Lukas Köhler", "Judith Skudelny", "Caren Lay", "Ralph Lenkert", "Eva-Maria Schreiber", "Hubertus Zdebel", "Lisa Badum", "Bettina Hoffmann", "Steffi Lemke"
                 , "Michael von Abercron", "Sybille Benning", "Ingo Gädechens", "Christian Haase", "Alexander Krauß", "Daniela Ludwig", "Florian Oßner", "Eckhard Pols", "Johannes Röring", "Stefan Sauer", "Reinhold Sendker", "Bernd Siebert", "Stephan Stracke", "Hans-Jürgen Thies", "Bela Bach", "Timon Gremmels", "Metin Hakverdi", "Marcus Held", "Arno Klare", "Isabel Mackensen", "Matthias Miersch", "René Röspel", "Udo Theodor Hemmelgarn", "Frank Magnitz", "Stephan Protschka", "Dirk Spaniel", "Karlheinz Busen", "Christoph Meyer", "Martin Neumann", "Frank Sitta", "Lorenz Gösta Beutin", "Victor Perli", "Ingrid Remmers", "Harald Weinberg", "Harald Ebner", "Oliver Krischer", "Christian Kühn", "Julia Verlinden", "Marco Bülow"
                 )

MP_1318_speeches$commember <- NA

for (i in 1:nrow(MP_1318_speeches)){
  MP_1318_speeches$commember[i] <- ifelse(MP_1318_speeches$name[i] %in% climate_com_18 & MP_1318_speeches$wp[i] == 18, 1,
                                          ifelse(MP_1318_speeches$name[i] %in% climate_com_19 & MP_1318_speeches$wp[i] == 19, 1, 0))
}


# add government dummy

MP_1318_speeches$mem_gov_party <- NA

for (i in 1:nrow(MP_1318_speeches)) {
MP_1318_speeches$mem_gov_party[i] <- ifelse(MP_1318_speeches$party[i] %in% c("Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union", "Fraktion der Sozialdemokratischen Partei Deutschlands"), 1, 0)
}

#rename parties from parliamentary group to actual parties

MP_1318_speeches$party[MP_1318_speeches$party == "Fraktion der Christlich Demokratischen Union/Christlich - Sozialen Union"] <- "CDU/CSU"

MP_1318_speeches$party[MP_1318_speeches$party == "Fraktion Bündnis 90/Die Grünen"] <- "Greens"

MP_1318_speeches$party[MP_1318_speeches$party == "Alternative für Deutschland"] <- "AfD"

MP_1318_speeches$party[MP_1318_speeches$party == "Fraktion der Freien Demokratischen Partei"] <- "FDP"

MP_1318_speeches$party[MP_1318_speeches$party == "Fraktion der Sozialdemokratischen Partei Deutschlands"] <- "SPD"

MP_1318_speeches$party[MP_1318_speeches$party == "Fraktion DIE LINKE."] <- "The Left"

# remove MPs without party

table(MP_1318_speeches$party)

MP_1318_speeches <- MP_1318_speeches[MP_1318_speeches$party %in% c("CDU/CSU","Greens", "AfD","FDP", "SPD", "The Left"),]

# add seat share variable (data from ParlGov data set)
MP_1318_speeches$seatshare <- NA

#WP 18
MP_1318_speeches$seatshare[MP_1318_speeches$party == "CDU/CSU" & MP_1318_speeches$wp == 18] <- 49.29

MP_1318_speeches$seatshare[MP_1318_speeches$party == "Greens" & MP_1318_speeches$wp == 18] <- 9.98

MP_1318_speeches$seatshare[MP_1318_speeches$party == "The Left" & MP_1318_speeches$wp == 18] <- 10.14

MP_1318_speeches$seatshare[MP_1318_speeches$party == "SPD" & MP_1318_speeches$wp == 18] <- 30.59

#WP19
MP_1318_speeches$seatshare[MP_1318_speeches$party == "CDU/CSU" & MP_1318_speeches$wp == 19] <- 34.7

MP_1318_speeches$seatshare[MP_1318_speeches$party == "Greens" & MP_1318_speeches$wp == 19] <- 9.4

MP_1318_speeches$seatshare[MP_1318_speeches$party == "The Left" & MP_1318_speeches$wp == 19] <- 9.7

MP_1318_speeches$seatshare[MP_1318_speeches$party == "SPD" & MP_1318_speeches$wp == 19] <- 21.6

MP_1318_speeches$seatshare[MP_1318_speeches$party == "FDP" & MP_1318_speeches$wp == 19] <- 11.3

MP_1318_speeches$seatshare[MP_1318_speeches$party == "AfD" & MP_1318_speeches$wp == 19] <- 13.3


#add parliamentary group leader dummy

MP_1318_speeches$parlgroupleader <- NA

#EP18
MP_1318_speeches$parlgroupleader[MP_1318_speeches$name %in% c("Volker Kauder", # CDU
                                                                  "Frank-Walter Steinmeier", "Thomas Oppermann", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Gregor Gysi", "Dietmar Bartsch", "Sarah Wagenknecht" #The Left
                                                                  ) & MP_1318_speeches$wp == 18] <- 1
                                   
#EP19
MP_1318_speeches$parlgroupleader[MP_1318_speeches$name %in% c("Christian Lindner", #FDP
                                                                  "Ralph Brinkhaus", # CDU
                                                                  "Rolf Mützenich", "Andrea Nahles", #SPD
                                                                  "Katrin Göring-Eckardt", "Anton Hofreiter", #Greens
                                                                  "Dietmar Bartsch", "Amira Mohamed Ali", #The Left
                                                                  "Alice Weidel", "Eberhardt Alexander Gauland" #AfD
                                                                  ) & MP_1318_speeches$wp == 19] <- 1
MP_1318_speeches$parlgroupleader[is.na(MP_1318_speeches$parlgroupleader)] <- 0
```


```{r data for models 4, echo = FALSE}
Z2 <- as.data.frame(MP_1318_speeches[, c("climate_speechcount", "age", "share_below_35", "share35_59", "share_above_60", "commember", 
                                           "party", "direct", "female", "expdummy", "parlgroupleader", "seatshare", "share_no_job", "wp", "year")])

```

```{r regression 4, echo = FALSE}
m10  <- glm.nb(climate_speechcount ~ age
              + share_below_35
           #   + share35_59
          #    + share_above_60
              + commember
              #+ party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
              + seatshare
              + share_no_job
              , data = Z2)


m11 <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
              + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
            #  + seatshare
              + share_no_job
              , data = Z2)

m12 <- glm.nb(climate_speechcount ~ age
              + share_below_35
              + share35_59
              + share_above_60
              + commember
             # + party
              + direct #explanatory variables
              + female # MP level controls
              + expdummy
             # + parlgroupleader
              + seatshare
              + share_no_job
              , data = Z2)

# Creates Table 2 from paper
stargazer(m10,m7,
          title  = "Determinants of the number of MPs’ speeches in debates on climate change",
          #label = "Table 2",
       #   covariate.labels = c("Age", "Constituency share below 35","Constituency share 35-59", "Constituency share above 60", "Committee Member", "Directly Elected", "Female", "Reelected", "Party Seatshare", "Unemployment rate in Constituency"),
          dep.var.caption = "Negative Binomial Model",
          dep.var.labels =  "Speeches on climate change by MP per year",
          column.labels = c("2013-2018", "2019-2021"),
          model.numbers = F,
          #type = stargazer_opt,
          type = "text",
          header = F,
          column.sep.width = "0.5pt",
          out = "table2.doc")
```


```{r compare before after 2019 effect}
plot13 <- plot_model(m10, type = "eff", terms = "age", title = "", axis.title = c("MPs' Age", "Speeches on Climate Change per Year"))
plot19 <- plot_model(m7, type = "eff", terms = "age", title = "", axis.title = c("MPs' Age", "Speeches on Climate Change per Year"))

# Creates figure 5 from the paper
figure2 <- ggarrange(plot13, plot19, 
                    labels = c("2013-2018", "2019-2021"),
                    ncol = 2, nrow = 1)
figure2
```

```{r figure 2}
pdf(file="2019_split.pdf")
figure2
dev.off()
```

#plot issue saliency

```{r}
# import data
saliency_dta <- read_excel("FGW_polbar_Probleme_1 2.xlsx") 

colnames(saliency_dta)<- c("date", "COVID", "Environment", "Immigration", "Education", "Pensions", "Social Inequality")
```
```{r}
# Creates Figure 1 from the paper
saliencyplot <- ggplot() +
    geom_line(data=saliency_dta, aes(x=date, y = COVID, color = "COVID"))  +
    geom_line(data=saliency_dta, aes(x=date, y = Environment, color = "Environment and Climate Issues")) +
    geom_line(data=saliency_dta, aes(x=date, y = Immigration, color = "Immigration"))  +
    geom_line(data=saliency_dta, aes(x=date, y = Education, color = "Education"))  +
    geom_line(data=saliency_dta, aes(x=date, y = Pensions, color = "Pensions"))  +
    geom_line(data=saliency_dta, aes(x=date, y = `Social Inequality`, color = "Social Inequality"))  +
    labs(x = "Year", y = "Share of respondents in %") +
    scale_color_manual(name = "", values = c( "COVID" = "#D55E00", "Environment and Climate Issues" = "#009E73", "Immigration" = "#56B4E9", "Education" = "#CC79A7", "Pensions" = "#999999", "Social Inequality" = "#E69F00")) 

```

```{r saliencyplot}
pdf(file="issue_saliency.pdf")
saliencyplot
dev.off()
```



